package com.dz.Incubator.service.impl;

import com.dz.Incubator.dao.SysUserDao;
import com.dz.Incubator.service.SysUserService;
import com.dz.Incubator.config.Pagination;
import com.dz.Incubator.entity.SysUserEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class SysUserServiceImpl implements SysUserService {

    private static final Logger logger = LoggerFactory.getLogger(SysUserService.class);

    @Autowired
    private SysUserDao sysUserDao;

    @Override
    public SysUserEntity insert(SysUserEntity sysUserEntity) {
        sysUserDao.insert(sysUserEntity);

        return sysUserEntity;
    }

    @Override
    public SysUserEntity update(SysUserEntity sysUserEntity) {
        sysUserDao.update(sysUserEntity);

        return sysUserEntity;
    }

    @Override
    public Integer delete(Long id) {
        int ret = sysUserDao.delete(id);
        return ret;
    }

    @Override
    public List<SysUserEntity> find(Long[] ids) {
        List<SysUserEntity> datas = sysUserDao.find(ids);
        return datas;
    }

    @Override
    public SysUserEntity get(Long id) {
        SysUserEntity sysUserEntity = sysUserDao.get(id);
        return sysUserEntity;
    }

    @Override
    public List<SysUserEntity> findAll() {
        List<SysUserEntity> datas = sysUserDao.findAll();
        return datas;
    }

    @Override
    public Pagination findByPagination(Pagination pagination) {
        List<SysUserEntity> datas = sysUserDao.findByPagination(pagination);
        pagination.setList(datas);
        return pagination;
    }

    @Override
    public List<SysUserEntity> insertBatch(List<SysUserEntity> list) {
        int ret = sysUserDao.insertBatch(list);
        return list;
    }

    @Override
    public List<SysUserEntity> updateBatch(List<SysUserEntity> list) {
        int ret = sysUserDao.updateBatch(list);
        return list;
    }

    @Override
    public List<Long> deleteBatch(Long[] ids) {
        int ret = sysUserDao.deleteBatch(ids);
        List<SysUserEntity> datas = sysUserDao.find(ids);
        List<Long> list = new ArrayList<Long>();
        for (SysUserEntity data : datas) {
            list.add(data.getId());
        }
        return list;
    }

    @Override
    public SysUserEntity findByOpenId(String openId) {
        return this.sysUserDao.findByOpenId(openId);
    }

    @Override
    public void bindPhone(int id, String phoneNumber) {
        this.sysUserDao.bindPhone(id, phoneNumber);
    }

    @Override
    public SysUserEntity findByPhone(String phoneNumber) {
        return sysUserDao.findByPhone(phoneNumber);
    }
}